﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace jQuery.Samples.MyWorks._06.res
{
    /// <summary>
    /// e 的摘要说明
    /// </summary>
    public class e : IHttpHandler
    {
        //private ArrayList EntryList = new ArrayList();


        Entry[] EntryList = new Entry[]{
            new Entry() { Term = "EAVESDROP", Part = "v.i.", Definition = "Secretly to overhear a catalogue of the crimes and vices of another or yourself.", Quote = "A lady with one of her ears applied, To an open keyhole heard, inside", Author = "Gopete Sherany" },
            new Entry() { Term = "EDIBLE", Part = "adj.", Definition = "Good to eat, and wholesome to digest, as a worm to a toad, a toad to a snake, a snake to a pig,a pig to a man, and a man to a worm.", Quote = "", Author = "" },
            new Entry() { Term = "ENVY", Part = "n.", Definition = "Emulation adapted to the meanest capacity.", Quote = "", Author = "" },
            new Entry() { Term = "EPITAPH", Part = "n.", Definition = "An inscription on a tomb, showing that virtues acquired by death have a retroactive effect.Following is a touching example:", Quote = "", Author = "" },
            new Entry() { Term = "EVANGELIST", Part = "n.", Definition = "A bearer of good tidings, particularly(in a religious sense) such as assure us of our own salvation and the damnation of our neighbors.", Quote = "", Author = "" }
            };
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            var term = context.Request.Params["term"];
            var isExist = false;
            if(!string.IsNullOrEmpty(term))
            {
                foreach (Entry item in EntryList)
                {
                    if(term.Trim().ToUpper()==item.Term)
                    {
                        isExist = true;
                        var html ="<div class='entry'><h3 class='term'>" + item.Term + "</h3><div class='part'>" + item.Part +
                        "</div><div class='definition'>" + item.Definition + "<div class='quote'>" + item.Quote +
                        "<div class='quote-author'>" + item.Author + "</div></div></div></div>";
                        context.Response.Write(html);
                    }
                }
                if(!isExist)
                    context.Response.Write("Sorry, your term was not found.");
            }
            else
            {
                context.Response.Write("Sorry, your term was not found.");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    public class Entry
    {
        public string Term { get; set; }
        public string Part { get; set; }
        public string Definition { get; set; }
        public string Quote { get; set; }
        public string Author { get; set; }
    }
}